<div class="tabmenu" style="position: relative;">
    <?php include template('layout/submenu'); ?>
</div>

<link rel="stylesheet" href="/packages/resource/pintuer/pintuer.css">
<script src="/packages/resource/pintuer/pintuer.js"></script>
<div class="pintuer">

    <?php
        if (!empty($_GET['id'])) {
            $info = ml('we_groupbuy')->find($_GET['goods_id']);
            $ginfo = ml('goods')->find($info['goods_id']);
            $gminfo = ml('goods_common')->find($ginfo['goods_commonid']);
        }
        if (!$info) {
            $info = [];
        }

        if (count($_POST)) {
            //查找商品
            $goods = Model()->table('goods_common')->where([
                'goods_serial' => trim($_POST['goods_id']),
                'store_id'     => $_SESSION['store_id'],

            ])->find();

            if (!$goods) {
    ?>
                <script>
                    layer.msg("未找到该商品");
                </script>
    <?php
            }

            $goods = Model()->table('goods')->where(['goods_commonid' => $goods['goods_commonid']])->find();
            $data = $_POST;
            $data['goods_serial'] = $_POST['goods_id'];
            $data['goods_id'] = $goods['goods_id'];
            $data['start_time'] = strtotime($_POST['start_time']);
            $data['end_time'] = strtotime($_POST['end_time']);
            $data['store_id'] = $_SESSION['store_id'];
            if (empty($_POST['id'])) {
                $data['id'] = null;
            }

            $flag = Model('we_groupbuy')->insert($data,true);
            if ($flag) {
        ?>
            <script>
                layer.msg("保存成功", function () {
                    location.href = '/shop/?act=we_groupbuy&op=goods';
                });
            </script>
    <?php
            }
        }
    ?>

    <form action="/shop/?act=we_groupbuy&op=add" method=post class="form-x padding-top">
        <input type="hidden" name="id" value="<?php echo $_GET['id'] ?>">
        <div class="form-group">
            <div class="label">
                团购名：
            </div>
            <div class="field">
                <input type="text" class="input" name="activity_name" value="<?php echo $info['activity_name']?>" data-validate="required:团购名不能为空">
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                开始时间：
            </div>
            <div class="field">
                <input type="text" class="input " id="start_time" name="start_time" value="<?php echo date("Y-m-d H:i:s",$info['start_time'])?>" readonly data-validate="required:开始时间不能为空">
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                结束时间：
            </div>
            <div class="field">
                <input type="text" class="input " id="end_time" name="end_time" value="<?php echo date("Y-m-d H:i:s",$info['end_time'])?>" readonly data-validate="required:结束时间不能为空">
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                商品货号：
            </div>
            <div class="field">
                <input type="text" class="input " name="goods_id" value="<?php echo $info['goods_serial']?>" data-validate="required:商品货号不能为空,ajax#/shop/?act=seccode&op=check_goods_id&goods_id=:该商品不存在">
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                最大人数：
            </div>
            <div class="field">
                <input type="text" class="input " name="max_person" value="<?php echo $info['max_person']?>" data-validate="required:最大人数不能为空,plusinteger:人数格式错误">
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                团购价格：
            </div>
            <div class="field">
                <div class="input-group" >
                    <input type="text" class="input "  name="price" value="<?php echo $info['price']?>" data-validate="required:价格不能为空,currency:团购价格格式错误">
                    <span class="addon">
                        元
                    </span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="label">
                详情描述：
            </div>
            <div class="field fixpintuer">
                <style>
                    .fixpintuer *{
                        box-sizing: content-box !important;
                    }
                </style>
                <script id="editor_cn" type="text/plain" style="width:800px;height:400px"><?php echo $info['content']?></script>
            </div>
        </div>

        <link href="/data/resource/umeditor/themes/default/css/umeditor.min.css" type="text/css" rel="stylesheet">
        <script type="text/javascript" charset="utf-8" src="/data/resource/umeditor/umeditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="/data/resource/umeditor/umeditor.min.js"></script>
        <script type="text/javascript" src="/data/resource/umeditor/lang/zh-cn/zh-cn.js"></script>
        <script>
            var serverPath = '/data/resource/umditor/php/',
                um_cn = UM.getEditor('editor_cn', {
                    imageUrl: serverPath + "imageUp.php",
                    imagePath: serverPath,
                    lang: /^zh/.test(navigator.language || navigator.browserLanguage || navigator.userLanguage) ? 'zh-cn' : 'en',
                    focus: false,
                    autoFloatEnabled: false,
                    textarea: 'content'
                });
        </script>

        <div class="line margin-top text-center">
            <button class="button bg-yellow" type="submit">提交</button>
        </div>


    </form>

    <script src="/packages/resource/laydate/laydate.js"></script>
    <script>
        var start = {
            elem: '#start_time',
            format: 'YYYY/MM/DD hh:mm:ss',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function(datas){
//                end.min = datas; //开始日选好后，重置结束日的最小日期
//                end.start = datas //将结束日的初始值设定为开始日

                $('#start_time').trigger('blur');
            }
        };
        var end = {
            elem: '#end_time',
            format: 'YYYY/MM/DD hh:mm:ss',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function(datas){
                $('#end_time').trigger('blur');

//                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    </script>

    <script>
        $('button[type=submit]').click(function () {


        })
    </script>


</div>